<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>用户管理</title>
    <link rel="stylesheet" type="text/css" href="/css/style.css" charset="utf-8" />

    <style type="text/css">
        *, body {
            margin: 0px;
            font-family: '微软雅黑';
        }
    </style>
    <script src="~/js/jquery-1.10.2.min.js"></script>
    <script src="~/js/generic.js"></script>
    <script src="~/js/fypage.js"></script>
</head>

<body>
<!--<div th:replace="top::top"></div>-->

<table class="maintable" style="width: 100%">
    <tr>
<!--        <div th:replace="menu::menu"></div>-->
        <td class="rightmaintd" valign="top">
            <div style="height: 40px; text-align: center; background-color: #009966">
                <p style="font-weight: bold; padding-top: 10px; font-size: larger; color: white">用户管理</p>
            </div>

            <div class="searchdiv">
                <input type="button" value="+新建用户" class="denglubtn" onclick="createAdmin();">
                <input type="button" value="+批量添加" class="denglubtn" onclick="BatchAdd();">
                <div class="rightsearchdiv"><!-- name -->
                    <div class="rightsearchdivtext">
                        <input type="text" id="keyword" class="nobodertext" placeholder="查询用户">
                        <button class="searchbtn" onclick="search();">
                            <img src="/images/fdj.png" alt="" class="searchfdj">
                        </button>
                    </div>
                </div>
            </div>
            <table class="neirontbiao" id="tbl_list" style="width: 100%"></table>

            <div class="pagediv" id="pager"></div>

        </td>
    </tr>
</table>

<!--<div th:replace="bottom::bottom"></div>-->

<script th:inline="javascript">
    var submit = false;
    var pager;
    $(document).ready(function () {
        pager = new Fypager("pager", getList);
        getList();
    });

    function createAdmin() {
        location.href = "/User/edit";
    }

    function BatchAdd() {
        location.href = "/User/batchAdd";
    }

    function updateAdmin(userid) {
        location.href = "/User/edit/" + userid;
    }

    window.onload = function () {}

    function deleteAdmin(userid) {
        if (confirm("确认删除用户吗")) {
            util.post("/User/delete", { "id": userid }, function (json) {
                if (json.status == 0) {
                    getList();
                } else {
                    alert(json.msg);
                }
            });
        }
    }

    function search() {
        pager.goPage(1);
    }

    //获取用户列表
    function getList() {
        var url = "/User/GetList?pageIndex=" + pager.currPage + "&pageSize=" + pager.pageNum;
        util.getJSON(url, { "keyword": $("#keyword").val() }, function (json) {
            if (json.status == 0) {
                pager.showPager(json.totalPage, json.totalNum, json.pageCount);
                showList(json.list);
            } else {
                alert(json.msg);
            }
        });
    }

    // 展示用户列表
    function showList(list) {
        var html = '<tr class="neirontbiaotou"><td width="10%">用户名</td><td width="10%">姓名</td><td width="15%">类型</td><td width="15%">电话</td><td width="15%">团队</td><td width="19%">院系单位</td><td width="10%"></td></tr>';
        if (list.length == 0) {
            html += '<tr><td colspan="7" style="text-align: center; height: 50px;">暂无用户</td></tr>';
        }
        for (var i = 0; i < list.length; i++) {
            html += '<tr>';
            html += '<td title="' + list[i].userid + '">' + [[${#strings.abbreviate(list[i].userid, 10) }]] + '</td>';
            html += '<td title="' + list[i].username + '">' + [[${#strings.abbreviate(list[i].username, 10) }]] + '</td>';
            html += '<td title="' + list[i].type + '">' + [[${#strings.abbreviate(list[i].type, 10) }]] + '</td>';
            html += '<td>' + [[${list[i].tel}]] + '</td>';
            html += '<td>' + [[${list[i].teamName}]] + '</td>';
            html += '<td>' + [[${list[i].company}]] + '</td>';
            html += '<td>' + '<a style="" href="javascript:updateAdmin(\'' + list[i].userid + '\')">编辑</a>&nbsp;<a style=";color:#0c531f" href="javascript:deleteAdmin(\'' + list[i].userid + '\')">删除</a>' + '</td></tr>';
        }
        $("#tbl_list").html(html);
    }
</script>
</body>
</html>
